/**
 * Created by Shinelon on 2017-12-05.
 */
$(function () {
	var hao = $("#ying10").val();
	$("#yuan9").text(hao);
	$("#yuan8").text(hao);
    // 顶部导航栏
    $('.ban').hide()
    $('.fanding').hide()
    $(document).scroll(function () {
        var fangda = $(document).scrollTop();
        if (fangda > 160) {
            $('.ban').slideDown(500);
        } else if (fangda <= 160) {
            $(".ban").slideUp(500);
        }
        if (fangda>600) {
            $('.fanding').fadeIn(1000)
        } else if (fangda <= 600) {
            $('.fanding').fadeOut(1000)
        }
    });
    $('#erji1').hide()
    //$('#erji2').hide()
    // 二级菜单
    $('#shouji').mouseenter(function () {
        $('#erji1').slideDown(500);
    })
    $('#shouji').mouseleave(function () {
        $('#erji1').mouseenter(function () {
            $('#erji1').show();
        }).mouseleave(function () {
            $('#erji1').slideUp(500);
        })
    })
    $('#shouji2').mouseenter(function () {
        $('#erji2').slideDown(500);
    })
    $('#shouji2').mouseleave(function () {
        $('#erji2').mouseenter(function () {
            $('#erji2').show();
        }).mouseleave(function () {
            $('#erji2').slideUp(500);
        })
    })

    // 返回顶部
    $('#tu2').hide()
    $('.fanding').mouseenter(function () {
        $('#tu2').fadeIn(500)
    }).mouseleave(function () {
        $('#tu2').fadeOut(500)
    })
    $('.fanding').click(function () {
        $('body,html').animate({scrollTop:0},500)
    })

    // 广告
    $('.tu>div>ul>li>div').mouseenter(function () {
        $(this).children('div').css('display','block')
        $(this).parent().css('box-shadow','0 0 50px #C1C1C1 inset')
        $(this).children('p:last').css('color','#fff')
    })
    $('.tu>div>ul>li>div').mouseleave(function () {
        $(this).children('div').css('display','none')
        $(this).parent().css('box-shadow','0 0 0px #fff inset')
        $(this).children('p:last').css('color','red')
    })
    // 热门商品
    $('.er>ul>li').mouseenter(function () {
        $(this).children('div').children('div').css('display','block')
        $(this).css('box-shadow','0 0 50px #C1C1C1 inset')
        $(this).children('div').children('p:last').css('color','#fff')
    })
    $('.er>ul>li').mouseleave(function () {
        $(this).children('div').children('div').css('display','none')
        $(this).css('box-shadow','0 0 0px #fff inset')
        $(this).children('div').children('p:last').css('color','red')
    })
    // 相同
    $('.nei>div>ul>li').mouseenter(function () {
        $(this).children('div').children('div').css('display','block')
        $(this).css('box-shadow','0 0 50px #C1C1C1 inset')
        $(this).children('div').children('p:last').css('color','#fff')
    })
    $('.nei>div>ul>li').mouseleave(function () {
        $(this).children('div').children('div').css('display','none')
        $(this).css('box-shadow','0 0 0px #fff inset')
        $(this).children('div').children('p:last').css('color','red')
    })
    var hao = []
    $('.yinchang').click(function () {
            var lidom = $(this).parent('div');
            var jia = {};
            jia.img = lidom.children('img').attr('src');
            jia.ming = lidom.children('p').first().text();
            var s = lidom.children('p').last().text();

            var img = lidom.children('img').attr('src');
            var ming = lidom.children('p').first().text();
            var qian = s.substring(1,s.length);
            
            var jian = lidom.children('p').last().prev().text();
            
            $("#tianjia").load("gouwuche.do",{"tu":img,"ming":ming,"zhi":jian,"qian":qian},function(result){
            	if(result==1){
            		window.location.href ="denglu.jsp";
            	}else{
    	       		$("#yuan9").text(result);
    	           	$("#yuan8").text(result);
            	}
            })
            
            
            jia.shuliang = 1;
            if(hao.length<=0){
                hao.push(jia);
            }else{
                for(var i = 0;i<hao.length;i++){
                    if(hao[i].ming == jia.ming){
                        hao[i].shuliang+=1;
                        break;
                    }
                    if(i==hao.length-1){
                        hao.push(jia);
                        break;
                    }
                }
            }
            $('.yuan').css('background-color','red')

            var huan = JSON.stringify(hao);
            sessionStorage.setItem('shu',huan);
})
    $('.yinchang2').click(function () {
        var lidom = $(this).parent('div');
        var jia = {};
        jia.img = lidom.children('img').attr('src');
        jia.ming = lidom.children('p').first().text();
        var s = lidom.children('p').last().text();

        var img = lidom.children('img').attr('src');
        var ming = lidom.children('p').first().text();
        var qian = s.substring(1,s.length);
        
        var jian = lidom.children('p').last().prev().text();
        
        $("#tianjia").load("gouwuche.do",{"tu":img,"ming":ming,"zhi":jian,"qian":qian},function(result){
        	if(result==1){
        		window.location.href ="denglu.jsp";
        	}else{
	       		$("#yuan9").text(result);
	           	$("#yuan8").text(result);
        	}
        })
        
        
        jia.shuliang = 1;
        if(hao.length<=0){
            hao.push(jia);
        }else{
            for(var i = 0;i<hao.length;i++){
                if(hao[i].ming == jia.ming){
                    hao[i].shuliang+=1;
                    break;
                }
                if(i==hao.length-1){
                    hao.push(jia);
                    break;
                }
            }
        }
        $('.yuan').css('background-color','red')
        if(hao.length == 0){
            $('.yuan').css('background-color','#fff')
        }
        
        var huan = JSON.stringify(hao);
        sessionStorage.setItem('shu',huan);
        
        
    })


});